package com.ml.framework.tools;

import java.util.Date;

import org.apache.commons.beanutils.Converter;

public class DateConverter implements Converter
{
	@Override
	public Object convert(Class type, Object value)
	{
		if (value == null)
			return null;

		if (type.equals(String.class))
		{
			if (value instanceof Date)
				return DateTimeUtils.convertToString((Date) value, DateTimeUtils.FMT_YYYYMMDDHHMMSS);
			else
				return String.valueOf(value);
		}
		else if (type.equals(Date.class))
		{
			if (value instanceof String)
				return DateTimeUtils.convertToDate((String) value);
			else
				return value;
		}
		return value;
	}
}
